﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Resto.CostControl.Core.Cache;
using Resto.CostControl.Core.Facade.DishModule.DataTransferObject;
using Resto.CostControl.Core.Domain.Model;

namespace Resto.CostControl.Core.Facade.DishOrderModule.DataTransferObject
{
    /// <summary>
    /// 订单项
    /// </summary>
    [Serializable]
    public class DishOrderItemDTO
    {
        #region 构造函数

        public DishOrderItemDTO() { }

        /// <summary>
        /// 根据菜肴Id来生成对象
        /// </summary>
        /// <param name="dishId"></param>
        public DishOrderItemDTO(string dishId)
        {
            DishDTO dish = DishDTOCache.Get(dishId);
            if (dish != null)
            {
                this.DishId = dish.ID;
                this.DishName = dish.Name;
                this.DishPrice = dish.Price;
                this.DishCost = dish.Cost;
            }
        }

        internal DishOrderItemDTO(DishOrderItem item)
        {
            this.Count = item.Count;
            this.DishCost = item.DishCost;
            this.DishId = item.DishID;
            this.DishName = item.DishName;
            this.DishPrice = item.DishPrice;            
        }

        #endregion

        #region 基本属性

        /// <summary>
        /// 菜肴Id,可为空
        /// </summary>
        public string DishId { get; set; }

        /// <summary>
        /// 菜肴的名称
        /// </summary>
        public string DishName { get; set; }

        /// <summary>
        /// 订购数量
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 单份菜肴的成本
        /// </summary>
        public decimal DishCost { get; set; }

        /// <summary>
        /// 菜肴的成本汇总
        /// </summary>
        public decimal TotalCost
        {
            get
            {
                return DishCost * Count;
            }
        }

        /// <summary>
        /// 菜肴的定价
        /// </summary>
        public decimal DishPrice { get; set; }

        /// <summary>
        /// 菜肴的预计总收入
        /// </summary>
        public decimal TotalPrice
        {
            get
            {
                return DishPrice * Count;
            }
        }

        #endregion

        #region 方法

        internal DishOrderItem ToDishOrderItem()
        {
            return new DishOrderItem()
            {
                Count = this.Count,
                DishCost = this.DishCost,
                DishID = this.DishId,
                DishName = this.DishName,
                DishPrice = this.DishPrice,
                TotalCost = this.TotalCost,
                TotalPrice = this.TotalPrice,
            };
        }

        #endregion
    }
}
